package com.charles.bigdata.mapreduce.phone;

import java.io.IOException;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

public class PhoneReducer extends Reducer<Text, FlowBean, Text, FlowBean> {

	@Override
	protected void reduce(Text k3, Iterable<FlowBean> v3, Context context) {

		// 对v3求和
		long upFlow = 0;
		long dFlow = 0;
		long sumFlow = 0;
		for (FlowBean v : v3) {
			upFlow += v.getUpFlow();
			dFlow += v.getdFlow();
			sumFlow += v.getSumFlow();
		}

		// 输出   k4 单词   v4  频率
		try {
			context.write(k3, new FlowBean(upFlow, dFlow, sumFlow));
		} catch (IOException e) {
			e.printStackTrace();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
}